<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/iconfont.css">
    <link rel="stylesheet" href="../../css/base.css">
    <script src="../../js/jquery-1.11.0.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../js/frameAll.js"></script>
    <style>
        .layui-form {
            margin-top: 30px;
        }
    </style>
</head>
<body>
<div class="cBody">
    <form id="addForm" class="layui-form" lay-filter="infoForm">
        <div class="layui-form-item">
            <label class="layui-form-label">原始密码 : </label>
            <div class="layui-input-inline shortInput">
                <input type="password" name="password" autocomplete="off" class="layui-input"
                       placeholder="请输入您的原始密码" lay-verify="password">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新&ensp;密&ensp;码 : </label>
            <div class="layui-input-inline shortInput">
                <input type="password" name="newPassword" autocomplete="off" class="layui-input"
                       placeholder="请输入新密码" lay-verify="newPassword">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">重复密码 : </label>
            <div class="layui-input-inline shortInput">
                <input type="password" name="rePassword" autocomplete="off" class="layui-input"
                       placeholder="请重复输入新密码" lay-verify="rePassword">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-radius" lay-submit lay-filter="submitBut">
                    修&nbsp;&nbsp;&nbsp;&nbsp;改
                </button>
                &nbsp;
                <button class="layui-btn layui-btn-radius layui-btn-primary" type="reset">重&nbsp;&nbsp;&nbsp;&nbsp;置
                </button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(submitBut)', function (data) {
            var field = data.field;
            $.ajax({
                type: "post",
                url: "/fixedAsset/updatePassword.do",
                data: field,
                dataType: "Json",
                success: function (data) {
                    switch (data.code) {
                        case 0:
                            top.location.href="../../login.html";
                            break;
                        case 1:
                            noMsg(data.message);
                            break;
                        default:
                    }
                },
                error: function () {
                    noMsg("连接服务器失败");
                }
            });
            return false;
        });
        form.verify({
            newPassword: function (value) {
                if (!/^[\S]{6,12}$/.test(value)) {
                    return '密码必须6到12位，且不能出现空格！';
                } else if ($('input[name=password]').val() === value) {
                    return '新密码与原始密码相同！';
                }
            },
            rePassword: function (value) {
                if ($('input[name=newPassword]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });
    });
</script>
</body>
</html>